import request from '@/utils/request'

/**
 * 查询配送单列表
 * @param {Object} query - 查询参数，包括分页、筛选条件等
 * @returns {Promise} - 返回配送单数据和分页信息
 */
export function listDelivery(query) {
    return request({
        url: '/delivery/deliveryOrder/list',
        method: 'get',
        params: query,
    });
}

/**
 * 更新配送单
 * @param {Object} data - 配送单信息
 * @returns {Promise} - 返回新增操作结果
 */
export function updateDelivery(data) {
    return request({
        url: '/delivery/deliveryOrder/update',
        method: 'put',
        data: data,
    });
}

/**
 * 获取明细信息
 * @param {String} deliveryBatchId - 配送单批次ID
 * @param {Object} query - 查询参数
 * @returns {Promise} - 返回配送单明细信息
 */
export function getDelivery(deliveryBatchId,query) {
    return request({
        url: `/delivery/deliveryDetail/detail/${deliveryBatchId}`,
        method: 'get',
        params: query,
    });
}

/**
 * 获取当前物流信息
 * @param {String} deliveryId - 配送单ID
 * @returns {Promise} - 返回物流信息
 */
export function getLogistics(deliveryId) {
    return request({
        url: `/delivery/logisticInfo`,
        method: 'get',
        params: { deliveryId },
    });
}

/**
 * 获取所有历史物流信息
 * @param {String} deliveryId - 配送单ID
 * @returns {Promise} - 返回物流信息
 */
export function getLogisticsHistory(deliveryId) {
    return request({
        url: `/delivery/logisticInfo/history`,
        method: 'get',
        params: { deliveryId },
    });
}

/**
 * 获取某个车辆的所有历史物流信息
 * @param {String} vehicleNumber - 车辆编号
 * @returns {Promise} - 返回物流信息
 */
export function getLogisticsHistoryByVehicle(vehicleNumber) {
    return request({
        url: `/delivery/logisticInfo/historyByVehicle`,
        method: 'get',
        params: {vehicleNumber},
    });
}

/**
 * 根据运单号获取配送单ID
 * @param trackingNo
 * @returns {deliveryId} deliveryId
 */
// export function getDeliveryIdByTrackingNo(trackingNo){
//     return request({
//         url: `/delivery/deliveryDetail/deliveryId/trackingNo`,
//         method: 'post',
//         data: trackingNo,
//     });
// }

export function getDeliveryIdByTrackingNo(trackingNo) {
        return request({
            url: `/delivery/deliveryDetail/getDeliveryIdByTrackingNo`,
            method: 'post',
            params: { trackingNo },
        });
    }
// export function getDeliveryIdByTrackingNo(trackingNo) {
//         return request({
//             url: `/delivery/deliveryDetail/getDeliveryIdByTrackingNo`,
//             method: 'get',
//             params: { trackingNo },
//         });
//     }

